package com.hangwei.aicabinet.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hangwei.aicabinet.R;
import com.hangwei.aicabinet.model.bean.OrderBean;
import com.hangwei.aicabinet.net.API;

import java.util.List;

/**
 * author: 张龙臣
 * date: 2018-08-27.
 */

public class OrderAdapter extends BaseQuickAdapter<OrderBean, BaseViewHolder> {


    public OrderAdapter(int layoutResId, @Nullable List<OrderBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderBean item) {
        if (item.checked)
            helper.setBackgroundColor(R.id.itemOrder, mContext.getResources().getColor(R.color.white));
        else
            helper.setBackgroundColor(R.id.itemOrder, mContext.getResources().getColor(R.color.background));
        helper.setText(R.id.tvOrderNum, item.ordernum);
        helper.setText(R.id.tvNum,item.orderentryNumber+"");
        RecyclerView recyclerView = helper.itemView.findViewById(R.id.recyclerView);
        LinearLayoutManager layout = new LinearLayoutManager(mContext);
        layout.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layout);
        ImageViewAdapter adapter = new ImageViewAdapter(item.picSet);

        recyclerView.setAdapter(adapter);
    }

    private class ImageViewAdapter extends RecyclerView.Adapter<MyViewHolder> {

        private List<String> picSet;

        public ImageViewAdapter(List<String> picSet) {
            this.picSet = picSet;
        }

        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_order_pic, null);
            return new MyViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
            holder.setIV(picSet.get(position));
        }

        @Override
        public int getItemCount() {
            return picSet.size();
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        public MyViewHolder(View itemView) {
            super(itemView);
        }

        public void setIV(String url) {
            SimpleDraweeView imageView = itemView.findViewById(R.id.imageView);
            imageView.setImageURI(API.BASE_URL_UNDER_LINE + url);
        }
    }

}
